<?php

namespace App\Model;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;

class Position extends Model
{
    //
    use SoftDeletes;
    protected $dates = ['deleted_at'];
    protected $table = 'positions';

    protected $fillable = [
        'bistro_id', 'name', 'qr_code', 'servant_count', 'wx_qr_code'
    ];

    public function scopeName($query, $name) {
        if(!empty($name)){
            return $query->where('name', 'like', '%'.$name.'%');
        }
        return $query;
    }

    public function scopeServantCount($query, $start, $end) {
        if(!empty($start) && !empty($end)) {
            $query->where('servant_count', '>', $start)->where('servant_count', '<', $end);
        }
        if(!empty($start)) {
            $query->where('servant_count', '>', $start);
        }
        if(!empty($end)) {
            $query->where('servant_count', '<', $end);
        }
        return $query;
    }

    public function bistro() {
        return $this->belongsTo('App\Model\Bistro');
    }
}
